package mobi.weq.model.vo;

import java.util.ArrayList;
import java.util.List;

import mobi.weq.model.SensorObservation;
import mobi.weq.util.edinburgh.EdinburghMap;
import mobi.weq.util.map.Coordinate;

public class GridVo {
	private double gridSize;
	private Coordinate southWest;
	private Coordinate northEast;
	private List<SensorObservation> observations;

	public GridVo(List<SensorObservation> observations) {
		if (observations == null) {
			observations = new ArrayList<SensorObservation>();
		}
		this.setObservations(observations);
		setGridSize(EdinburghMap.GRID_SIZE);
		double maxLat = -Double.MAX_VALUE;
		double maxLng = -Double.MAX_VALUE;
		double minLat = Double.MAX_VALUE;
		double minLng = Double.MAX_VALUE;

		for (SensorObservation o : observations) {
			if (o.getLatitude() > maxLat) {
				maxLat = o.getLatitude();
			}

			if (o.getLatitude() < minLat) {
				minLat = o.getLatitude();
			}

			if (o.getLongitude() > maxLng) {
				maxLng = o.getLongitude();
			}
			
			if (o.getLongitude() < minLng) {
				minLng = o.getLongitude();
			}
		}
		this.setSouthWest(new Coordinate(minLat, minLng));
		this.setNorthEast(new Coordinate(maxLat, maxLng));
	}

	public double getGridSize() {
		return gridSize;
	}

	public void setGridSize(double gridSize) {
		this.gridSize = gridSize;
	}

	public Coordinate getSouthWest() {
		return southWest;
	}

	public void setSouthWest(Coordinate southWest) {
		this.southWest = southWest;
	}

	public Coordinate getNorthEast() {
		return northEast;
	}

	public void setNorthEast(Coordinate northEast) {
		this.northEast = northEast;
	}

	public List<SensorObservation> getObservations() {
		return observations;
	}

	public void setObservations(List<SensorObservation> observations) {
		this.observations = observations;
	}
}
